/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.game.web.adv;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.game.entity.adv.HkGameSystemAdv;
import com.thinkgem.jeesite.modules.hk.game.service.adv.HkGameSystemAdvService;

/**
 * 游戏广告Controller
 * @author 罗天文
 * @version 2018-10-31
 */
@Controller
@RequestMapping(value = "${adminPath}/game/adv/hkGameSystemAdv")
public class HkGameSystemAdvController extends BaseController {

	@Autowired
	private HkGameSystemAdvService hkGameSystemAdvService;
	
	@ModelAttribute
	public HkGameSystemAdv get(@RequestParam(required=false) String id) {
		HkGameSystemAdv entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkGameSystemAdvService.get(id);
		}
		if (entity == null){
			entity = new HkGameSystemAdv();
		}
		return entity;
	}
	
	@RequiresPermissions("game:adv:hkGameSystemAdv:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkGameSystemAdv hkGameSystemAdv, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkGameSystemAdv> page = hkGameSystemAdvService.findPage(new Page<HkGameSystemAdv>(request, response), hkGameSystemAdv); 
		model.addAttribute("page", page);
		return "hk/game/adv/hkGameSystemAdvList";
	}

	@RequiresPermissions("game:adv:hkGameSystemAdv:view")
	@RequestMapping(value = "form")
	public String form(HkGameSystemAdv hkGameSystemAdv, Model model) {
		model.addAttribute("hkGameSystemAdv", hkGameSystemAdv);
		return "hk/game/adv/hkGameSystemAdvForm";
	}

	@RequiresPermissions("game:adv:hkGameSystemAdv:edit")
	@RequestMapping(value = "save")
	public String save(HkGameSystemAdv hkGameSystemAdv, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkGameSystemAdv)){
			return form(hkGameSystemAdv, model);
		}
		hkGameSystemAdvService.save(hkGameSystemAdv);
		addMessage(redirectAttributes, "保存游戏广告成功");
		return "redirect:"+Global.getAdminPath()+"/game/adv/hkGameSystemAdv/?repage";
	}
	
	@RequiresPermissions("game:adv:hkGameSystemAdv:edit")
	@RequestMapping(value = "delete")
	public String delete(HkGameSystemAdv hkGameSystemAdv, RedirectAttributes redirectAttributes) {
		hkGameSystemAdvService.delete(hkGameSystemAdv);
		addMessage(redirectAttributes, "删除游戏广告成功");
		return "redirect:"+Global.getAdminPath()+"/game/adv/hkGameSystemAdv/?repage";
	}

}